<?

function connectDB($mysql_host,$mysql_user,$mysql_password) {

$con = mysql_connect($mysql_host,$mysql_user,$mysql_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  return -1;
  }
return $con;
}

function writeDB($con,$mysql_database,$stazIn, $stazOut, $gg, $mm, $aa, $hh, $min, $nreq, $mail){
mysql_select_db($mysql_database, $con);

mysql_query("INSERT INTO destinazione(stazIn, stazOut, aa, mm, gg, hh, min, nreq, mail)
VALUES ($stazIn, $stazOut, $aa, $mm, $gg, $hh, $min, $nreq, $mail)");
mysql_close($con);
}

function readDB($con,$mysql_database){
mysql_select_db($mysql_database, $con);
$result = mysql_query("SELECT * FROM destinazione");
if (!$result) {
    die('Invalid query: ' . mysql_error());
}  
mysql_close($con);
return $result;
}

function pulisciDB($con,$mysql_database){	
	date_default_timezone_set('Europe/Rome');
	$data_com=$ieri = date('d m Y', mktime(0,0,0,date(m),date(d)-1,date(Y)));
	echo $data_com;
	$data=split(' ',$data_com);
	mysql_select_db($mysql_database, $con);
	echo "delete FROM destinazione where aa='".$data[2]."' and  mm='".$data[1]."' and  gg='".$data[0]."'";
	$result = mysql_query("delete FROM destinazione where aa='".$data[2]."' and  mm='".$data[1]."' and  gg='".$data[0]."'");
	if (!$result) {
		die('Invalid query: ' . mysql_error());
	}	
	return $result;
}

function sendMail($a, $oggetto, $messaggio) {
$intestazioni= "MIME-Version: 1.0\r\n";
$intestazioni.= "Content-type: text/html; charset=iso-8859-1\r\n";
$intestazioni.= "From:<info treno> info@treno.site11.com";
//echo "send mail : ". $a." ".$oggetto." ".$messaggio;
mail($a, $oggetto, $messaggio, $intestazioni);
}
?>